import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/title_view.dart';
import 'package:flutter_eve_plugin/model/health/user_body_property.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class WeightAdviceWidget extends StatelessWidget {
  const WeightAdviceWidget({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(state: store.state),
        builder: (context, vm) {
          List<UserBodyDataInfo> infoList =
              vm.state.headlthState.userBodyModel.data;
          var weightList = infoList?.where((item) {
            return item.name == '体重';
          })?.toList();
          UserBodyDataInfo bodyInfo;
          if (weightList == null || weightList.isEmpty) {
            bodyInfo = UserBodyDataInfo('', '', '', 0, '', '', 0, 0, 0, 0, '',
                0, 0, 0, '', 0, '', '', '', '', '', null, '', null, '');
          } else {
            bodyInfo = weightList?.first;
          }
          return Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(imageUtilHuPo('health/icon_dotted_border@2x')),
                  fit: BoxFit.fill),
            ),
            child: Stack(
              children: <Widget>[
                Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    SizedBox(
                      height: setRatio(25),
                    ),
                    HealthTitleViewWidget(
                      title: '体重建议',
                    ),
                    Container(
                        padding: EdgeInsets.only(
                            left: setRatio(20),
                            right: setRatio(20),
                            top: setRatio(25)),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            RichText(
                              softWrap: true,
                              text: TextSpan(
                                text: '你的琥珀现在是',
                                style: TextStyle(
                                  color: Color.fromRGBO(51, 51, 51, 1),
                                  fontSize: setTextSp(14),
                                  fontWeight: FontWeight.w400,
                                ),
                                children: [
                                  buildTextSpan(bodyInfo),
                                  TextSpan(
                                    text: '哦！',
                                    style: TextStyle(
                                      color: Color.fromRGBO(51, 51, 51, 1),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            SizedBox(
                              height: setRatio(15),
                            ),
                            Text(
                              bodyInfo.weightPropose,
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: Color(0xFF333333),
                                  fontSize: setTextSp(14)),
                            ),
                          ],
                        )),
                    SizedBox(
                      height: setRatio(27),
                    ),
                    Center(
                      child: Container(
                        padding: EdgeInsets.only(
                            top: setRatio(6),
                            bottom: setRatio(6),
                            left: setRatio(10),
                            right: setRatio(10)),
                        child: Text(
                          '合理的饮食，一定的运动，是完美身材的来源',
                          style: TextStyle(
                              color: Color.fromRGBO(153, 153, 153, 1),
                              fontSize: setTextSp(11)),
                        ),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(204, 204, 204, 1),
                          borderRadius: BorderRadius.circular(setRatio(5)),
                        ),
                      ),
                    ),
                    SizedBox(
                      height: setRatio(24),
                    )
                  ],
                ),
                bodyInfo.weightGrade == 3
                    ? Positioned(
                        left: setRatio(252),
                        top: setRatio(57),
                        child: Image.asset(
                          imageUtilHuPo('health/icon_perfect@2x'),
                          width: setRatio(61),
                          height: setRatio(63),
                        ))
                    : Container()
              ],
            ),
            width: setRatio(345),
          );
        });
  }

  TextSpan buildTextSpan(UserBodyDataInfo info) {
    ///1 骨瘦如柴； 2 身材偏瘦； 3 完美身材; 4 身体偏胖； 5 肥胖如猪
    switch (info.weightGrade) {
      case 1:
      case 5:
        return TextSpan(
          text: info.weightType,
          style: TextStyle(
            color: Color(0xFFF73E3E),
          ),
        );
      case 2:
      case 4:
        return TextSpan(
          text: info.weightType,
          style: TextStyle(
            color: Color(0xFFF89D1A),
          ),
        );
      case 3:
        return TextSpan(
          text: info.weightType,
          style: TextStyle(
            color: Color(0xFF7F79FF),
          ),
        );
    }
    return TextSpan();
  }
}
